package cn.wolfcode.mp.web.controller;


import cn.wolfcode.mp.qo.JsonResult;
import cn.wolfcode.mp.service.IRoleService;
import cn.wolfcode.mp.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("roles")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @GetMapping("/list")
    @RequiredPermission(name = "角色页面",expression = "role:list")
    public JsonResult list(){
        return new JsonResult(roleService.list());
    }

    @DeleteMapping("/delete")
    @RequiredPermission(name = "角色删除",expression = "role:delete")
    public JsonResult delete(Long id){
        roleService.removeById(id);
        return new JsonResult();
    }

    @GetMapping("/permission")
    @RequiredPermission(name = "角色删除",expression = "role:delete")
    public JsonResult permission(Long roleId){
        boolean flag = roleService.permission(roleId);
        String msg = "可以访问";
        if (!flag){
            msg = "权限不够";
        }
        return new JsonResult(flag,msg);
    }


}
